﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.huigo.Framework.ServiceUtils;
using System.Text;

namespace com.huigo.B2B.Web.center.order
{
    public partial class OrderDetail : BasePage
    {
        private long OrderId
        {
            get
            {
                return com.loto.Common.Utils.IsNumeric(Request.QueryString["id"]) ? Convert.ToInt64(com.loto.Common.Utils.SqlEscape(Request.QueryString["id"])) : long.MinValue;
            }
        }
        public int statusFid = 0;
        public string payAmount = "0.00";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (OrderId > 0)
            {
                int insType = 0;//保单类型

                List<RequestFuncParams> list = new List<RequestFuncParams>();
                list.Add(new RequestFuncParams("sid", OrderId.ToString()));
                BaseService service = new BaseService();
                ParserXml parser = service.RequestEntryService(Dict.ERequestFunc.GET_ORDER_INFO_BY_ID, list);
                if (parser != null && parser.RowsCount > 0)
                {
                    payAmount = Convert.ToDecimal(parser["OrderPayAmount", 0]).ToString("0.00");
                    insType = Convert.ToInt16(parser["OrderInsTypeFid", 0].ToString());
                    statusFid = Convert.ToInt32(parser["OrderStatusFid", 0]);
                    rptProduct.DataSource = parser.ModelList;
                    rptProduct.DataBind();
                }
                list.Add(new RequestFuncParams("orderFid", OrderId.ToString()));
                string theadFormat = "<table class=\"table table-bordered table-striped responsive-utilities table-hover\"><thead><tr><th colspan=\"12\">被保人信息</th></tr><tr><th>序号</th><th>姓名</th><th>证件类型</th><th >证件号</th><th>出生日期</th><th>性别</th><th>航班号</th><th>保险起期</th><th>手机号码</th><th>电子邮箱</th><th>保单号</th><th>保单状态</th></tr></thead><tbody>{0}</tbody></table>";
                string tbodyFormat = "<tr><td>{0}</td><td>{1}</td><td/>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td><td>{8}</td><td>{9}</td><td>{10}</td><td>{11}</td></tr>";
                StringBuilder sb = new StringBuilder();
                switch (insType)
                {
                    case (int)Dict.InsType.Air:
                        parser = service.RequestEntryService(Dict.ERequestFunc.GET_POLICY_INFO_AIR_LIST, list);
                        if (parser != null && parser.RowsCount > 0)
                        {
                            for (int i = 0; i < parser.RowsCount; i++)
                            {
                                sb.AppendFormat(tbodyFormat, i + 1, parser["PolicyHolderName", i].ToString(), parser["PolicyHolderCredentialType", i].ToString(), parser["PolicyHolderCredentialNo", i].ToString(), Convert.ToDateTime(parser["PolicyHolderBirth", i].ToString().Replace("T", " ")).ToString("yyyy-MM-dd"), parser["PolicyHolderGender", i].ToString(), parser["PolicyFlightNo", i].ToString(), Convert.ToDateTime(parser["PolicyFromPeriod", i].ToString().Replace("T", " ")).ToString("yyyy-MM-dd"), parser["PolicyInsuredTel", i].ToString(), parser["PolicyInsuredEmail", i].ToString(), parser["PolicyNo", i].ToString(), parser["StatusDesc", i].ToString(), parser["PolicyId", i].ToString());
                            }
                            litOrderList.Text = string.Format(theadFormat, sb.ToString());
                        }
                        break;
                    case (int)Dict.InsType.Travel:
                        theadFormat = "<table class=\"table table-bordered table-striped responsive-utilities table-hover\"><thead><tr><th colspan=\"12\">被保人信息</th></tr><tr><th>序号</th><th>姓名</th><th>证件类型</th><th >证件号</th><th>出生日期</th><th>性别</th><th>航行线路</th><th>保险起期</th><th>手机号码</th><th>电子邮箱</th><th>保单号</th><th>保单状态</th></tr></thead><tbody>{0}</tbody></table>";
                        parser = service.RequestEntryService(Dict.ERequestFunc.GET_POLICY_INFO_TRAVEL_LIST, list);
                        if (parser != null && parser.RowsCount > 0)
                        {
                            for (int i = 0; i < parser.RowsCount; i++)
                            {
                                sb.AppendFormat(tbodyFormat, i + 1, parser["PolicyHolderName", i].ToString(), parser["PolicyHolderCredentialType", i].ToString(), parser["PolicyHolderCredentialNo", i].ToString(), Convert.ToDateTime(parser["PolicyHolderBirth", i].ToString().Replace("T", " ")).ToString("yyyy-MM-dd"), parser["PolicyHolderGender", i].ToString(), parser["PolicyTravelLine", i].ToString(), Convert.ToDateTime(parser["PolicyFromPeriod", i].ToString().Replace("T", " ")).ToString("yyyy-MM-dd"), parser["PolicyInsuredTel", i].ToString(), parser["PolicyInsuredEmail", i].ToString(), parser["PolicyNo", i].ToString(), parser["StatusDesc", i].ToString(), parser["PolicyId", i].ToString());
                            }
                            litOrderList.Text = string.Format(theadFormat, sb.ToString());
                        }

                        break;
                }
            }
        }
        /// <summary>
        /// 未支付状态时显示操作按钮
        /// </summary>
        /// <returns></returns>
        public string OrderStatus()
        {
            string content = "<div style=\"text-align:center;\">订单总金额：<span class=\"red bold\" style=\"font-size:18px;\">￥" + payAmount + "</span></div><br/><div style=\"text-align: center\"><input type=\"button\" value=\"取消订单\" class=\"btn-big btn-orange\" onclick=\"CancelOrder('" + OrderId + "')\" />&nbsp;&nbsp;<input type=\"button\" value=\"去支付\" class=\"button btn-big btn-orange\" onclick=\"payOrder('" + OrderId + "')\" /></div>";
            if (statusFid == 1)
            {
                return content;
            }
            else
            {
                return string.Empty;
            }
        }
    }
}
